package com.qf.erpb.core.common;

public class JsonResult<T> {


    private Integer code;//状态码
    private String msg;//返回的是消息的说明
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 成功返回的方法
     *
     * @return
     */
    public static JsonResult ok() {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(200);
        jsonResult.setMsg("success");
        return jsonResult;
    }

    public static <T> JsonResult ok(T data) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(200);
        jsonResult.setMsg("success");
        jsonResult.setData(data);
        return jsonResult;
    }

    public static <T> JsonResult ok(int code, T data) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(0);
        jsonResult.setMsg("success");
        jsonResult.setData(data);
        return jsonResult;
    }

    /**
     * 失败返回的方法
     *
     * @return
     */
    public static JsonResult error() {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(500);
        jsonResult.setMsg("fail");
        return jsonResult;
    }

    public static JsonResult error(String msg) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(500);
        jsonResult.setMsg(msg);
        return jsonResult;
    }
}
